<template>
    <div class="todo-footer">
        <label for="input-1">
            <input type="checkbox" id="input-1" :checked="isAll" @change="checkedAll($event)">
        </label>
        <span>
            <span>已完成</span>
            <span class="f-r">（{{doneTotal}}）</span>
            <span>/&nbsp;</span>
            <span>全部</span>
            <span class="f-r">（{{todoList.length}}）</span>
        </span>
        <button class="btn btn-danger" @click="clearAllDone">清除已完成的任务</button>
    </div>
</template>

<script>
    export default {
        name: "Footer",
        props: ["todoList", "checkAll", "clearDone"],
        data() {
            return {
                count: 0
            }
        },
        methods: {
            // 全选或取消全选
            checkedAll(event) {
                console.log(event.target.checked);
                this.checkAll(event.target.checked);
            },
            // 清除全部已完成todo
            clearAllDone() {
                console.log(this);
                this.clearDone();
            }
        },
        computed: {
            doneTotal() {
                return this.todoList.reduce((pre, current) => {
                    // console.log(pre,current);
                    return pre + (current.done ? 1 : 0);
                }, 0);
            },
            isAll() {
                return this.todoList.length === this.doneTotal && this.doneTotal > 0;
            }
        }
    }
</script>

<style scoped lang="less">
    /*footer*/
    .todo-footer {
        height: 40px;
        line-height: 40px;
        padding-left: 6px;
        margin-top: 5px;
        label {
            display: inline-block;
            margin-right: 20px;
            cursor: pointer;
            input {
                position: relative;
                top: -1px;
                vertical-align: middle;
                margin-right: 5px;
            }
        }
        button {
            float: right;
            margin-top: 5px;
        }
    }
</style>